home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / reduce / rweb / rweave.ch < prev    next >
Encoding:
Text File  |  1992-01-01  |  6.5 KB  |  210 lines

  1. % Copyright (c) 1991: Marcel Roelofs and Peter Gragert
  2. %                     University of Twente, Enschede, The Netherlands
  3. % @@(#) rweave.ch (91/03/11)
  4.  
  5. @x
  6.     if (isdigit(c)) @<Get a constant@>@; /*spider*/
  7.     else if (isalpha(c) || c=='_') @<Get an identifier@>@;/*spider*/
  8.     else if (c=='\'' || c=='"') @<Get a string@>@;/*spider*/
  9. @y
  10.     if (isdigit(c)) @<Get a constant@>@;/*spider*/
  11.     else if (isalpha(c) || c=='_' || c=='!') @<Get an identifier@>@;/*spider*/
  12.     else if (c=='\"') @<Get a string@>@;/*spider*/
  13. @z
  14.  
  15. @x
  16. @ @<Get an identifier@>= {/*spider*/
  17.   id_first=--loc;
  18.   while (isalpha(*++loc) || isdigit(*loc) || *loc=='_');
  19.   id_loc=loc; return(identifier);
  20. }
  21. @y
  22. @ @<Get an identifier@>= {/*spider*/
  23.   id_first=--loc;
  24.   if (c=='!') ++loc;
  25.   while (isalpha(*++loc) || isdigit(*loc) || *loc=='_' || *loc=='!') 
  26.     if (*loc=='!') ++loc;
  27.   id_loc=loc; return(identifier);
  28. }
  29. @z
  30.  
  31. @x
  32. @ \cee\ strings and character constants, delimited by double and single
  33. quotes, respectively, can contain newlines or instances of their own
  34. delimiters if they are protected by a backslash.  We follow this
  35. convention, but do not allow the string to be longer than |longest_name|.
  36.  
  37. @<Get a string@>= {/*spider*/
  38.   ASCII delim = c; /* what started the string */
  39.   id_first = mod_text+1;
  40.   id_loc = mod_text;
  41.   if (delim=='`' && *(loc-2)==at_sign) {
  42.     /* make string begin with |"@@`"| */
  43.     *++id_loc=at_sign; 
  44.     *++id_loc=at_sign;
  45.     }
  46.     /* this is hack for ascii constant */
  47. @#
  48. /* if it's not a single-character literal, it's a tick mark or an |at_sign| */
  49.   if ((delim=='\'' || delim == '`') && 
  50.         (loc+1>=limit || 
  51.             (*loc != '\\' && *loc!=at_sign && loc[1]!='\'')    || 
  52.             (*loc=='\\' && (loc+2>=limit||loc[2]!='\'')) ||
  53.             (*loc==at_sign && 
  54.                 (loc+2>=limit||loc[1]!=at_sign||loc[2]!='\''))
  55.         )
  56.       ) goto mistake;
  57.   *++id_loc=delim;
  58.   if (delim=='`') delim='\''; /* for |ascii_constant|s */
  59.   while (1) {
  60.     if (loc>=limit) {
  61.       if(*(limit-1)!='\\') {
  62.         err_print("! String didn't end"); loc=limit; break;
  63. @.String didn't end@>
  64.       }
  65.       if(get_line()==0) {
  66.         err_print("! Input ended in middle of string"); loc=buffer; break;
  67. @.Input ended in middle of string@>
  68.       }
  69.     }
  70.     if ((c=*loc++)==delim) {
  71.       if (++id_loc<=mod_text_end) *id_loc=c;
  72.       break;
  73.     }
  74.     if (c=='\\') if (loc>=limit) continue;
  75.       else if (++id_loc<=mod_text_end) {
  76.         *id_loc = '\\'; c=*loc++;
  77.       }
  78.     if (++id_loc<=mod_text_end) *id_loc=c;
  79.   }
  80.   if (id_loc>=mod_text_end) {
  81.     printf("\n! String too long: ");
  82. @.String too long@>
  83.     ASCII_write(mod_text+1,25);
  84.     printf("..."); mark_error;
  85.   }
  86.   id_loc++;
  87.   return(string);
  88. }
  89. @y 
  90. @ \cee\ strings are delimited by double quotes and must be restricted
  91. to one line. Double quotes in strings must be doubled and we allow no
  92. string to be longer than |longest_name|.
  93.  
  94. @<Get a string@>= {/*spider*/
  95.   ASCII delim = c; /* what started the string */
  96. @#
  97.   id_first = mod_text+1;
  98.   id_loc = mod_text; *++id_loc=delim;
  99.   while (1) {
  100.     if (loc>=limit) {
  101.       err_print("! String didn't end"); loc=limit;
  102. @.String didn't end@>
  103.       if (get_line()==0) {
  104.         err_print("! Input ended in middle of string"); loc=buffer;
  105. @.Input ended in middle of string@>
  106.       }
  107.       break;
  108.     }
  109.     if ((c=*loc++)==delim) {
  110.       if (++id_loc<=mod_text_end) *id_loc=c;
  111.       if (*loc==delim) loc++;
  112.       else break;
  113.     }
  114.     if (++id_loc<=mod_text_end) *id_loc=c;
  115.   }
  116.   if (id_loc>=mod_text_end) {
  117.     printf("\n! String too long: ");
  118. @.String too long@>
  119.     ASCII_write(mod_text+1,25);
  120.     printf("..."); mark_error;
  121.   }
  122.   id_loc++;
  123.   return(string);
  124. }
  125. @z
  126.  
  127. @x
  128.       case 1: printf("\\{"); print_id((name_dir+r)); printf("}"); break;
  129.  /* |id_flag| */
  130.       case 2: printf("\&{"); print_id((name_dir+r)); printf("}"); break;
  131. @y
  132.       case 1: printf("\\\\{"); print_id((name_dir+r)); printf("}"); break;
  133.  /* |id_flag| */
  134.       case 2: printf("\\&{"); print_id((name_dir+r)); printf("}"); break;
  135. @z
  136.  
  137. @x
  138. @ @<Start a format...@>= {
  139.   app_str("\\F"); app_scrap(SP_ignore_scrap,no_math);
  140.       /* this will produce `\&{format}' */
  141. @.\\F@>
  142. @<Set |next_control| to the first non-newline token@>@;
  143. /* claim at this point |scrap_ptr==scrap_info+1| */
  144.   if (scrap_ptr!=scrap_info+1) {
  145.     err_print("! This can't happen -- bad scrap_ptr in format definition");
  146.     printf("\n\tscrap_ptr-scrap_info==%d\n",scrap_ptr-scrap_info);
  147.   }
  148.   if (next_control==identifier) {
  149.     small_app(id_flag+id_lookup(id_first, id_loc,normal)-name_dir);
  150.     app_str(" ");
  151.     app_scrap(SP_ignore_scrap,no_math); /*spider*/
  152.  /* this is syntactically separate from what follows */
  153.     @<Set |next_control| to the first non-newline token@>@;
  154.     if (next_control==identifier) {
  155.       small_app(id_flag+id_lookup(id_first, id_loc,normal)-name_dir);
  156.       small_app(@`\n');
  157.       app_scrap(SP_ignore_scrap,no_math);
  158.       @<Set |next_control| to the first non-newline token@>@;
  159.     }
  160.   }
  161.   /* if everything went well, we appended two scraps */
  162.   if (scrap_ptr!=scrap_info+3) err_print("! Improper format definition");
  163. @.Improper format definition@>
  164. }
  165. @y
  166. @ @<Start a format...@>= {
  167.   small_app(backup); app_str("\\F"); app_scrap(SP_ignore_scrap,no_math);
  168.       /* this will produce `\&{format}' */
  169. @.\\F@>
  170. @<Set |next_control| to the first non-newline token@>@;
  171. /* claim at this point |scrap_ptr==scrap_info+1| */
  172.   if (scrap_ptr!=scrap_info+1) {
  173.     err_print("! This can't happen -- bad scrap_ptr in format definition");
  174.     printf("\n\tscrap_ptr-scrap_info==%d\n",scrap_ptr-scrap_info);
  175.   }
  176.   if (next_control==identifier) {
  177.     small_app(id_flag+id_lookup(id_first, id_loc,normal)-name_dir);
  178.     app_str(" ");
  179.     app_scrap(SP_ignore_scrap,no_math); /*spider*/
  180.  /* this is syntactically separate from what follows */
  181.     @<Set |next_control| to the first non-newline token@>@;
  182.     if (next_control==identifier) {
  183.       small_app(id_flag+id_lookup(id_first, id_loc,normal)-name_dir);
  184.       small_app(@`\n');
  185.       app_scrap(SP_ignore_scrap,no_math);
  186.       @<Set |next_control| to the first non-newline token@>@;
  187.     }
  188.   }
  189.   /* if everything went well, we appended two scraps */
  190.   if (scrap_ptr!=scrap_info+2) err_print("! Improper format definition");
  191. @.Improper format definition@>
  192. }
  193. @z
  194.  
  195. @x
  196. if (cur_xref->num%def_flag!=module_count) {
  197.   app_str("+"); /*module name is multiply defined*/
  198.   this_module=name_dir; /*so we won't give cross-reference info here*/
  199. }
  200. app_str("\\S"); /* output an equivalence sign */
  201. @y
  202. if (cur_xref->num%def_flag!=module_count) {
  203.   app_str("\\PS"); /*module name is multiply defined*/
  204.   this_module=name_dir; /*so we won't give cross-reference info here*/
  205. }
  206. else app_str("\\S"); /* output an equivalence sign */
  207. @z
  208.  
  209.  
  210.